﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunny.Controls
{
	public class TableRow : System.Windows.Controls.RowDefinition
	{
		//private System.Windows.Controls.StackPanel _CellsContainer;
		//protected System.Windows.Controls.StackPanel CellsContainer
		//{
		//    get
		//    {
		//        if (this._CellsContainer == null)
		//            this._CellsContainer = new System.Windows.Controls.StackPanel();
		//        return this._CellsContainer;
		//    }
		//}

		private System.Windows.GridLength PreviousHeight;
		public bool Visible
		{
			get
			{
				return this.Height != new System.Windows.GridLength(0);
			}
			set
			{
				if (value)
					this.Height = this.PreviousHeight;
				else
				{
					this.PreviousHeight = this.Height;
					this.Height = new System.Windows.GridLength(0);
				}
			}
		}

		public TableRow()
		{
			//this.BorderBrush = System.Windows.Media.Brushes.Black;
			//this.BorderThickness = new System.Windows.Thickness(1, 1, 0, 0);

			//this.Child = this.CellsContainer;
			//Common.SynchronizeCollection(this.Cells, this.CellsContainer.Children);
		}

		public Table Table
		{
			get
			{
				return (Table)((System.Windows.Controls.Grid)this.Parent).Parent;
			}
		}

		private System.Collections.ObjectModel.ObservableCollection<TableCell> _Cells;
		public System.Collections.ObjectModel.ObservableCollection<TableCell> Cells
		{
			get
			{
				if (this._Cells == null)
				{
					this._Cells = new System.Collections.ObjectModel.ObservableCollection<TableCell>();
					this._Cells.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Cells_CollectionChanged);
				}
				return this._Cells;
			}
		}

		void Cells_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
		{
			if (e.NewItems == null)
				return;
			foreach (TableCell cell in e.NewItems)
				cell.Row = this;
		}
	}
}